package models

import "fmt"

type Video struct {
	Id    int     `gorm:"type:int(10);index"json:"id"`
	Name  string  `gorm:"type:varchar(20)"json:"name"`
	Price float64 `gorm:"type:float(10,2)"json:"price"`
	Img   string  `json:"img"`
	Intro string  `gorm:"type:varchar(255)"json:"intro"`
}

func MysqlList(page int, pageSize int, str string) ([]Video, int64, error) {
	var videos []Video
	var total int64
	if str != "" {
		fmt.Printf(" where like ?", "%"+str+"%")
	}
	if err = DB.Count(&total).Error; err != nil {
		return nil, 0, err
	}
	if err = DB.Order("price desc").Offset((page - 1) * pageSize).Limit(pageSize).Find(&videos).Error; err != nil {
		return nil, 0, err
	}
	return videos, total, err
}
